package com.yl.ylnews;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.Window;
import android.widget.FrameLayout;

import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;
import com.yl.ylnews.fragment.LeftMenuFragment;
import com.yl.ylnews.fragment.MainFragment;

/**
 * Created by Administrator on 2016/10/16 0016.
 */

public class MainActivity extends SlidingFragmentActivity {
    private static final String FRAGMENT_MAIN = "1";
    private static final String FRAGMENT_LEFT_MENU = "2";
    private android.widget.FrameLayout flmain;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        this.flmain = (FrameLayout) findViewById(R.id.fl_main);

        setBehindContentView(R.layout.fragment_left_menu);
        SlidingMenu slidingMenu = getSlidingMenu();
        int width = getWindowManager().getDefaultDisplay().getWidth();
        slidingMenu.setBehindWidth(width*140/320);
        slidingMenu.setTouchModeAbove(SlidingMenu.LEFT);

        initFragment();
    }

    private void initFragment() {
        FragmentManager fm = getSupportFragmentManager();
        FragmentTransaction ft = fm.beginTransaction();
        MainFragment mainFragment = new MainFragment();
        ft.replace(R.id.fl_main,mainFragment, FRAGMENT_MAIN);
        LeftMenuFragment leftMenuFragment = new LeftMenuFragment();
        ft.replace(R.id.fl_menu, leftMenuFragment, FRAGMENT_LEFT_MENU);
        ft.commit();
    }

    public MainFragment getContentFragment() {
        FragmentManager fm = getSupportFragmentManager();
        return (MainFragment) fm.findFragmentByTag(FRAGMENT_MAIN);
    }

    public LeftMenuFragment getMenuFragment() {
        FragmentManager fm = getSupportFragmentManager();
        return (LeftMenuFragment) fm.findFragmentByTag(FRAGMENT_LEFT_MENU);
    }
}
